<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Exchange extends CI_Controller{
    
    //Mang tham so nhan duoc o moi action
    protected $_arrParam;
    
    public function __construct(){
        parent::__construct();
        require_once(APPPATH . 'modules/backend/autoload.php');
		$this->load->language('backend');
		$this->smarty->assign('language', $this->lang);
		$this->smarty->assign('message',$this->session->flashdata('message'));
		$this->smarty->assign('error_message',$this->session->flashdata('error_message'));
        
        
        $jqxtheme = array(base_url() . 'library/jqwidgets/styles/jqx.darkblue.css');
        
        $jqueryui = array(base_url() . 'jscripts/jquery-ui/jquery-ui-1.8.21.min.js');
        
        $css_files = array(base_url() . 'jscripts/jqxGrid/styles/jqx.base.css');

        $js_files = array(
                base_url() . 'jscripts/jqxGrid/jqx-all.js'
        );
        
        //$this->smarty->assign('jqueryui', $jqueryui);
        $this->smarty->assign('jqxtheme', $jqxtheme);
        $this->smarty->assign('css_files', $css_files);
        $this->smarty->assign('js_files', $js_files);
        
        require_once(APPPATH . 'modules/backend/denied.php');
    }
    
    public function topup(){   
        $this->smarty->assign('title','Admin Panel - Giao dịch bắn tiền');
        $this->smarty->assign('heading','XEM GIAO DỊCH BẮN TIỀN');
        $jqxgrid_init = $this->smarty->get_contents('backend/js/grid_topup');
        $js_text = array($jqxgrid_init);
        $this->smarty->assign('js_text', $js_text);
        
        $this->smarty->view('backend/exchange/topup', 'grid');
        $this->smarty->display('backend/admin');
        
        $user = $this->login_manager->get_user();
        $aParamAdminLog=array(
                        'username'   => $user[0]->name,
                        'customerID' => $user[0]->customerID,
                        'email'      => $user[0]->email,
                        'lastLogin'  => date("Y-m-d H:i:s"),
                        'logAction'  => "Quản lý giao dịch: Bắn tiền",
                        'ip'         => $_SERVER['REMOTE_ADDR'],
                        'uID'        => $user[0]->uID
                        );
        $log = $this->db_user_model->insertUserAdminLog($aParamAdminLog);
    }
    
    public function data_json_topup(){
        if(IS_AJAX){          
			$data['rows'] = $this->db_exchange_model->gettopUp();
            $data['total_row'] = count($data['rows']);
            for($i = 0; $i < $data['total_row']; $i++){
                if($data['rows'][$i]->amount!=0){
                    $data['rows'][$i]->amount = vndformat($data['rows'][$i]->amount,'');//number_format($data['rows'][$i]->amount, 0, ',', '.');
                }
                
                $explode = explode(" ",$data['rows'][$i]->productValue);
                $data['rows'][$i]->productValue = $explode[0];
            }
			echo json_encode($data);
		}
    }
    
    public function buycard(){
        $this->smarty->assign('title','Admin Panel - Giao dịch mua thẻ');
        $this->smarty->assign('heading','XEM GIAO DỊCH MUA THẺ');
        $jqxgrid_init = $this->smarty->get_contents('backend/js/grid_bycard');
        $js_text = array($jqxgrid_init);
        $this->smarty->assign('js_text', $js_text);
        
        $this->smarty->view('backend/exchange/buycard', 'grid');
        $this->smarty->display('backend/admin');
        
        
        $user = $this->login_manager->get_user();
        $aParamAdminLog=array(
                        'username'   => $user[0]->name,
                        'customerID' => $user[0]->customerID,
                        'email'      => $user[0]->email,
                        'lastLogin'  => date("Y-m-d H:i:s"),
                        'logAction'  => "Quản lý giao dịch : Mua thẻ",
                        'ip'         => $_SERVER['REMOTE_ADDR'],
                        'uID'        => $user[0]->uID
                        );
        $log = $this->db_user_model->insertUserAdminLog($aParamAdminLog);
    }
    
    public function data_json_buycard(){
        if(IS_AJAX){          
			$data['rows'] = $this->db_exchange_model->getbuyCard();
            $data['total_row'] = count($data['rows']);
            for($i = 0; $i < $data['total_row']; $i++){
                if($data['rows'][$i]->amount!=0){
                    $data['rows'][$i]->amount = vndformat($data['rows'][$i]->amount,'');
                }
                
                $explode = explode(" ",$data['rows'][$i]->productValue);
                //$data['rows'][$i]->productValue = $explode[0];
            }
			echo json_encode($data);
		}
    }
    
    public function payment(){
        $this->smarty->assign('title','Admin Panel - Giao dịch thanh toán');
        $this->smarty->assign('heading','XEM GIAO DỊCH THANH TOÁN');
        $jqxgrid_init = $this->smarty->get_contents('backend/js/grid_payment');
        $js_text = array($jqxgrid_init);
        $this->smarty->assign('js_text', $js_text);
        
        $this->smarty->view('backend/exchange/payment', 'grid');
        $this->smarty->display('backend/admin');
        
        $user = $this->login_manager->get_user();
        $aParamAdminLog=array(
                        'username'   => $user[0]->name,
                        'customerID' => $user[0]->customerID,
                        'email'      => $user[0]->email,
                        'lastLogin'  => date("Y-m-d H:i:s"),
                        'logAction'  => "Quản lý giao dịch : Thanh toán",
                        'ip'         => $_SERVER['REMOTE_ADDR'],
                        'uID'        => $user[0]->uID
                        );
        $log = $this->db_user_model->insertUserAdminLog($aParamAdminLog);
    }
    
    public function data_json_payment(){
        if(IS_AJAX){          
			$data['rows'] = $this->db_exchange_model->getPayment();
            $data['total_row'] = count($data['rows']);
            for($i = 0; $i < $data['total_row']; $i++){
                if($data['rows'][$i]->amount!=0){
                    $data['rows'][$i]->amount = vndformat($data['rows'][$i]->amount,'');
                }
                
                $explode = explode(" ",$data['rows'][$i]->productValue);
                $data['rows'][$i]->productValue = $explode[0];
            }
			echo json_encode($data);
		}
    }
    
    public function vidientu(){
        $this->smarty->assign('title','Admin Panel - Ví điện tử');
        $this->smarty->assign('heading','XEM GIAO DỊCH VÍ ĐIỆN TỬ');
        $jqxgrid_init = $this->smarty->get_contents('backend/js/grid_vidientu');
        $js_text = array($jqxgrid_init);
        $this->smarty->assign('js_text', $js_text);
        
        $this->smarty->view('backend/exchange/vidientu', 'grid');
        $this->smarty->display('backend/admin');
        
        $user = $this->login_manager->get_user();
        $aParamAdminLog=array(
                        'username'   => $user[0]->name,
                        'customerID' => $user[0]->customerID,
                        'email'      => $user[0]->email,
                        'lastLogin'  => date("Y-m-d H:i:s"),
                        'logAction'  => "Quản lý giao dịch : Ví điện tử",
                        'ip'         => $_SERVER['REMOTE_ADDR'],
                        'uID'        => $user[0]->uID
                        );
        $log = $this->db_user_model->insertUserAdminLog($aParamAdminLog);
    }
    
    public function data_json_vidientu(){
        if(IS_AJAX){          
			$data['rows'] = $this->db_exchange_model->getVidientu();
            $data['total_row'] = count($data['rows']);
            for($i = 0; $i < $data['total_row']; $i++){
                if($data['rows'][$i]->amount!=0){
                    $data['rows'][$i]->amount = vndformat($data['rows'][$i]->amount,'');
                }
                
                $explode = explode(" ",$data['rows'][$i]->productValue);
                $data['rows'][$i]->productValue = $explode[0];
            }
			echo json_encode($data);
		}
    }
    
    public function vidoanhnghiep(){
        $this->smarty->assign('title','Admin Panel - Ví doanh nghiệp');
        $this->smarty->assign('heading','XEM GIAO DỊCH VÍ DOANH NGHIỆP');
        $jqxgrid_init = $this->smarty->get_contents('backend/js/grid_vidoanhnghiep');
        $js_text = array($jqxgrid_init);
        $this->smarty->assign('js_text', $js_text);
        
        $this->smarty->view('backend/exchange/vidoanhnghiep', 'grid');
        $this->smarty->display('backend/admin');
        
        $user = $this->login_manager->get_user();
        $aParamAdminLog=array(
                        'username'   => $user[0]->name,
                        'customerID' => $user[0]->customerID,
                        'email'      => $user[0]->email,
                        'lastLogin'  => date("Y-m-d H:i:s"),
                        'logAction'  => "Quản lý giao dịch : Ví doanh nghiệp",
                        'ip'         => $_SERVER['REMOTE_ADDR'],
                        'uID'        => $user[0]->uID
                        );
        $log = $this->db_user_model->insertUserAdminLog($aParamAdminLog);
    }
    
    public function data_json_vidoanhnghiep(){
        if(IS_AJAX){          
			$data['rows'] = $this->db_exchange_model->getVidoanhnghiep();
            $data['total_row'] = count($data['rows']);
            for($i = 0; $i < $data['total_row']; $i++){
                if($data['rows'][$i]->amount!=0){
                    $data['rows'][$i]->amount = vndformat($data['rows'][$i]->amount,'');
                }
                
                $explode = explode(" ",$data['rows'][$i]->productValue);
                $data['rows'][$i]->productValue = $explode[0];
            }
			echo json_encode($data);
		}
    }
    
}

/* End of file exchange.php */
/* Location: ./system/application/controllers/backend/exchange.php */